<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
/**
 * Basketball extension for Joomleague
 * @version $Id: show_players.tpl.php 98 2008-02-25 23:38:14Z julien.vonthron $
 * @package JlgBasketballExtension
 * @copyright Copyright (C) 2007 Julien Vonthron. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * JlgBasketballExtension is free software and parts of it may contain or be derived from the
 * GNU General Public License or other free or open source software licenses.
 * 
 * contact: julien.vonthron[at]gmail.com 
 *   
 * Joomleague is a League Management and Prediction Game for Joomla!
 * Homepage: http://www.joomleague.de 
 *  
 */
 
/**
 * returns true if the event stat should be displayed
 *
 * @param int $eventId
 * @return boolean  
 */   
function displayEvent($eventId)
{
    global $overall_config;
    $averages_event_set = array ( 
        $overall_config['event_3pt_made'],
        $overall_config['event_3pt_attempts'],
        $overall_config['event_fg_made'],
        $overall_config['event_fg_attempts'],
        $overall_config['event_ft_made'],
        $overall_config['event_ft_attempts'],
        $overall_config['event_ppg'],
        $overall_config['event_rpg'],
        $overall_config['event_apg'],
        $overall_config['event_spg'],
        $overall_config['event_bpg'],
        $overall_config['event_3pt_per'],
        $overall_config['event_fg_per'],
        $overall_config['event_ft_per']
                    );
    return in_array( $eventId, $averages_event_set );
}

/**
 * print formatted event stat
 *
 * @param int $eventId
 * @param int $stat value of the event stat
 */ 
function printEventStat($eventId, $stat)
{
    global $overall_config;
    switch ($eventId)
    {
        case $overall_config['event_ppg']:
        case $overall_config['event_rpg']:
        case $overall_config['event_apg']:
          printf( '%.1f', $stat );
          break;
        case $overall_config['event_spg']:
        case $overall_config['event_bpg']:
          printf( '%.2f', $stat );
          break;
        case $overall_config['event_3pt_per']:
        case $overall_config['event_fg_per']:
        case $overall_config['event_ft_per']:
          printf( '%.3f', $stat );
          break;
        default:
          printf( '%d', $stat );
          break;
    }
}
?>
<div class="joomleague">
<!-- Header with Project Name-->
<?php if ($showPlayers_config['show_project_heading'] == "1" OR $overall_config['show_project_heading'] == "1") { ?>
<div class="componentheading" <?php if ($showPlayers_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") echo 'style="float:left;"';?>><?php echo HTML_joomleague::showTitle($joomleague, $overall_config['project_heading_type']); ?></div>
<!-- Druckfunktion -->
<?php if ($showPlayers_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") {
HTML_joomleague::PrintIcon( $row, $params, false, '' );
};?>
<!-- Druckfunktion Ende -->
<?php } ?>
<!-- Header END -->

<!-- section header e.g. ranking, results etc. -->
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading"><?php echo _JL_PLAYERS_KADER;?> <?php echo $team->name;?> 
    <?php if ($showPlayers_config['show_team_shortform']==1) echo '[ '.$team->short_name.' ]' ;?></td>
	</tr>
</table>
<!-- section header END -->

<br />

<?php
if ($showPlayers_config['show_team_logo']==1) {
      $picture = (is_null($teamtool->picture)) ? "components/com_joomleague/images/placeholders/placeholder_450.png" : $teamtool->picture;
?>   
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <td align="center"><img src="<?php echo _JOOMLA_JL_LIVE_SITE; ?>/<?php echo $picture;?>" alt="<?php  echo $team->name?>" title="<?php  echo $team->name?>" /></td>
  </tr>  
</table>
<?php } ?>

<?php 
if(trim($teamtool->description !="")){ ?>
<br />
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="sectiontableheader">
		<td><?php echo _JL_PLAYERS_KADER_INFO;?></td>
	</tr>
</table>
  <table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
      <td>
        <?php echo $teamtool->description;?>
      </td>
  </tr>  
</table>
<?php
} 
?>

<br /><br />
<?php if (count($rows>0)) { ?>
<div id="jlg_teamroster">
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
<?php
  $k = 0;
  $position = "";
  for ($i=0, $n=count( $rows ); $i < $n; $i++) {
    $row = &$rows[$i];
    if($position != $row->position){
      $position = $row->position;
      $k = 0;
?>
      <tr class="sectiontableheader">
        <td width="60%" colspan="<?php 
            echo ((isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) ? '6' : '5'); ?>
            "><?php echo $position; ?>
        </td>
        <?php
        if ($showPlayers_config['show_stats']==1) { ?>
        <td align="center"><?php
          echo _JL_PLAYER_PLAYED;
          ?>
        </td>
        <?php
        if ( isset($overall_config['use_jl_substitution']) && $overall_config['use_jl_substitution'] == 1
            && $showPlayers_config['show_substitution_stats'] ) 
        {
          ?>
          <td align="center"><img src="<?php echo JL_TEMPLATE_FOLDERS_URL.'/images/in.png';?>" alt="<?php echo _JL_PLAYER_IN;?>" /></td>
          <td align="center"><img src="<?php echo JL_TEMPLATE_FOLDERS_URL.'/images/out.png';?>" alt="<?php echo _JL_PLAYER_OUT;?>" /></td>
          <?php
        }
        if (count ($PosEventtypes[$row->position_id]))
        {
          foreach ($PosEventtypes[$row->position_id] AS $eventtype) 
          {
            if (displayEvent($eventtype->eventtype_id)){
              echo '<td align="center"><img src="'.JL_TEMPLATE_FOLDERS_URL.'/images/event_icons/'.$eventtype->icon.'" alt="'.$eventtype->name.'" title="'.$eventtype->name.'" align="top" hspace="2" /></td>';
            }
          }
        }
 			}
      	?>
      </tr>
<?php
    }
    
?>
    <tr class="<?php echo ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2'; ?>">

      <td width="30" align="center">
<?php
if ($showPlayers_config['show_player_numbers']==1) {
	if ($showPlayers_config['player_numbers_pictures']==1 && function_exists('imagecreatefrompng')) { ?>
  <img src="<?php echo JL_TEMPLATE_FOLDERS_URL;?>/images/shirt.php?text=<?php echo ($row->position_number!=0) ? $row->position_number : '';?>" alt="<?php echo $row->position_number;?>" />
<?php
	}
	else { echo ($row->position_number!='') ? $row->position_number : '&nbsp;'; }
}
else echo '&nbsp;'; ?>
      </td>

<td width="40" align="center" nowrap="nowrap">
<?php if ($showPlayers_config['show_player_icon']==1) { 
$picture = ($row->picture!=''&&!is_null($row->picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$row->picture)) ? $row->picture : $row->default_picture;
if ($picture!=''&&!is_null($picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$picture)) {
$Thumb = new PowerThumb();
$Thumb->setSrc($picture);
$Thumb->setDescription($row->description);
$Thumb->setAlt($row->firstname." ".$row->lastname);
$Thumb->setMaxHeight(30);
$Thumb->setAmpliationLink(false);
//$Thumb->setFilter("gray");
$Thumb->create();
}
?>
<?php } ;?>
</td>

      <td style="width:20%;">
      <?php if ($showPlayers_config['link_player']==1) { ;?>
      <a href="<?php echo sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showPlayer&amp;p=$joomleague->id&amp;pid=$row->pid".JL_ITEMID_SUFFIX);?>">
      <?php printf("<i>%s %s</i>",$row->firstname,$row->lastname);?></a>
      <?php } 
      else printf("<i>%s %s</i>",$row->firstname,$row->lastname);?>
      </td>
      <td width="5%" align="left">
    	<?php if($row->injury > 0 && $row->injury_end > $joomleague->current_round){
        echo '<img src="'.JL_TEMPLATE_FOLDERS_URL.'images/injured.gif" alt="" />';
              }?>
    	<?php if($row->suspension > 0 && $row->suspension_end > $joomleague->current_round){
        echo '<img src="'.JL_TEMPLATE_FOLDERS_URL.'images/suspension.gif" alt="" />';
              }?>    
      </td>     
      <td style="width:16px;" nowrap="nowrap" align="left">
      <?php
      $thiscountry = new Country($database);
      $thiscountry->load($row->nation);
      echo $thiscountry->getFlag();
     ?>
      	</td>
  <?php if (isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) { ?>
      <td width="10%" nowrap="nowrap" align="left"><?php printf("%s (%s)", mbiFormatDate($row->birthday,_JL_PLAYERS_BIRTHDATE_DATE),
      getAge($row->birthday)); ?></td>
      <?php
    }
     if ($showPlayers_config['show_stats']==1) {
       // get starter/subs stats
     	 $inoutstat = BasketballProject::getStartInOutStats($row->player_id, $row->project_id, $row->team_id);

       if ($inoutstat->played > 0) {
       	 // played at least one game
         echo '<td align="center" nowrap="nowrap">'.$inoutstat->played;
         if ( isset($overall_config['use_jl_substitution']) 
                && $overall_config['use_jl_substitution'] == 1
                && $showPlayers_config['show_games_played'] )
         {
          echo ' <acronym title="'._JL_STARTING_ROSTERS.'">('
           .(($inoutstat->played - $inoutstat->sub_in > 0) ? $inoutstat->played - $inoutstat->sub_in : '-')
           .')</acronym>';
         }
         echo '</td>';
         
         // substitutions stats
         if (isset($overall_config['use_jl_substitution']) && $overall_config['use_jl_substitution'] == 1 
              && $showPlayers_config['show_substitution_stats']) {
           echo '<td align="center">'.(($inoutstat->sub_in > 0) ? $inoutstat->sub_in : '-').'</td>';
           echo '<td align="center">'.(($inoutstat->sub_out > 0) ? $inoutstat->sub_out : '-').'</td>';
         }
      }
      else {
      	// no games played
        echo '<td align="center">-</td>';
        if ( isset($overall_config['use_jl_substitution']) && $overall_config['use_jl_substitution'] == 1
            && $showPlayers_config['show_substitution_stats'] ) {
          echo '<td align="center">-</td><td align="center">-</td>';
        }
      }
      if (count ($PosEventtypes[$row->position_id]))
      {
        // print stats
        foreach ($playerStats[$row->id] AS $eventId => $stat) 
        {
          if ( displayEvent($eventId) )
      	  {
  	        ?>
  	        <td><?php printEventStat( $eventId, $stat );?></td>
            <?php
          }
        }
      }
	 }?>
    </tr>
<?php
    $k = 1 - $k;
  }
?>

</table>
<br /><br />
<?php if (count($stafflist) > 0) { ?>
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading"><?php echo _JL_PLAYERS_STAFF;?> <?php echo $team->name;?> 
    <?php if ($showPlayers_config['show_team_shortform']==1) echo '[ '.$team->short_name.' ]' ;?></td>
	</tr>
</table><br />
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="sectiontableheader">
    <td width="60%" colspan="<?php echo ((isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) ? '6' : '5').'">'._JL_PLAYERS_STAFFPOSITIONS;?></td>
    <td><?php echo _JL_PLAYERS_FUNCTION;?></td>  
  </tr>
<?php
  $k = 0;
  for ($i=0, $n=count( $stafflist ); $i < $n; $i++) {
    $row = &$stafflist[$i];
?>
  <tr class="<?php echo ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2'; ?>">
    <td width="30" align="center"> </td>
    <td width="40" align="center" nowrap="nowrap">
<?php if ($showPlayers_config['show_player_icon']==1) { 
$picture = ($row->picture!=''&&!is_null($row->picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$row->picture)) ? $row->picture : $row->default_picture;
if ($picture!=''&&!is_null($picture)&&file_exists(_JOOMLA_JL_PATH.'/'.$picture)) {
$Thumb = new PowerThumb();
$Thumb->setSrc($picture);
$Thumb->setDescription($row->description);
$Thumb->setAlt($row->firstname." ".$row->lastname);
$Thumb->setMaxHeight(30);
$Thumb->setAmpliationLink(false);
//$Thumb->setFilter("gray");
$Thumb->create();
}
?>
<?php } ;?>
</td>
    <td style="width:20%;">
    <?php if ($showPlayers_config['link_player']==1) { ;?>
    <a href="<?php echo sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showTeamstaff&amp;p=$joomleague->id&amp;pid=$row->id".JL_ITEMID_SUFFIX);?>">
    <?php printf("<i>%s %s</i>",$row->firstname,$row->lastname);?></a>
    <?php } 
    else printf("<i>%s %s</i>",$row->firstname,$row->lastname);?>
    </td>
    <td width="5%">&nbsp;</td>
    <td style="width:16px;" nowrap="nowrap" align="left">
      <?php
      $thiscountry = new Country($database);
      $thiscountry->load($row->nation);
      echo $thiscountry->getFlag();
     ?>
     </td>
  <?php if (isset($showPlayers_config['show_birthday']) && $showPlayers_config['show_birthday'] == 1) { ?>
     <td width="10%" nowrap="nowrap" align="left"><?php printf("%s (%s)", mbiFormatDate($row->birthday,_JL_PLAYERS_BIRTHDATE_DATE),
      getAge($row->birthday)); ?></td>
   <?php
    } ?>
    <td><?php print ($row->position); ?></td>
<?php
    $k = 1 - $k;
  }
?>   
</table>
</div>
<?php 
}
};?>

<!-- Print Button START -->
<?php if ($showPlayers_config['show_back_button'] > 0 OR $overall_config['show_back_button'] > 0) {;?>
<?php if ($showPlayers_config['show_back_button'] == "1" OR $overall_config['show_back_button'] == "1") echo '<div align="left">'; else echo '<div align="right">';?>
<?php
$params = & new mosParameters( '' );
$params->def( 'back_button', true );
$params->def( 'popup', false );
mosHTML::BackButton( $params );
?></div> 
<?php };?>
<!-- Print Button END -->
</div>
